package com.czf.testmodule.oss.controller;

import com.czf.testmodule.oss.entity.OssResult;
import com.czf.testmodule.oss.service.IOssService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;

/**
 * @author zfChen
 * @create 2022/5/19 15:47
 */
@RestController
@Slf4j
@CrossOrigin
public class OssController {

    @Autowired
    private IOssService ossService;

    @RequestMapping("/oss")
    public OssResult uploadOss(@RequestPart("file")MultipartFile file, HttpServletRequest req) {
        return ossService.upload(file);
    }

    @RequestMapping("/ossDownload")
    public ResponseEntity<Object> downloadOss(String fileName){
        return ossService.download(fileName);
    }
}
